<template>
  <div id="app" :class='{showLeftMenu: showLeftMenu}'>
    <!-- 关注二维码 -->
    <!-- <div class='qr-code-wrapper' v-show='showQrCode'>
      <div class='qr-code-box'>
        <span class='qr-code-title'>长按二维码，关注公众号</span>
        <img class='qr-code-img' :src="codeUrl">
      </div>
    </div> -->
    <subscribe-qrcode v-if='showWechatQr'
                      @close='showWechatQr = false'>
    </subscribe-qrcode>
    <router-view :key='$route.path + $route.query'/>
  </div>
</template>

<script>
import subscribeQrcode from '@/components/subscribe-qrcode'
// import { queryUrl } from '@/assets/js/utils'
import { Dialog } from 'vant'
export default {
  name: 'App',
  data () {
    return {
      showLeftMenu: false,
      showQrCode: false,
      codeUrl: '',
      showWechatQr: false
    }
  },
  methods: {
    goToUserCenter () {
      // this.$router.push({ name: '1287992954211799041' })
      this.$router.push({ name: 'registerIndex' })
    }
  },
  components: {
    subscribeQrcode
  },
  watch: {
    $route (newV, oldV) {
      this.showLeftMenu = false
    }
  },
  mounted () {
    // 调起关注公众号的二维码
    window.eventBus.$on('showWechatQr', () => {
      // 如果在非微信环境，不展示二维码
      // if (this.checkIfWxClient()) {
      this.showWechatQr = true
      // }
    })
    window.eventBus.$on('toggleLeftMenu', isShow => {
      this.showLeftMenu = isShow
    })
    // 显示注册引导弹框
    window.eventBus.$on('showRegisterGuide', desc => {
      Dialog.confirm({
        message: `您还未注册, 是否立即前往？`
      }).then(() => {
        this.$router.push({ name: 'registerDefault' })
      })
    })
    // 显示个人中心认证引导弹框
    window.eventBus.$on('showAuthGuide', desc => {
      Dialog.alert({
        message: `本内容只允许${desc}`,
        confirmButtonText: '去认证'
      }).then(() => {
        this.goToUserCenter()
      })
    })
    // 显示用户类型不匹配弹框
    window.eventBus.$on('showNotMatch', desc => {
      Dialog.alert({
        message: `本内容只允许${desc}`,
        confirmButtonText: '关闭'
      }).then(() => {
        this.closeWindow()
      })
    })
    if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
      window.entryUrl = document.location.href.split('#')[0]
    }
  },
  created () {
    // sessionStorage.setItem('appid', this.WXAPPID)
  }
}
</script>

<style lang="stylus">
@import './assets/styles/index'
#app
  width 100vw
  min-height 100vh
  background #fcfcfc
  transition all ease 0.3s
  &::-webkit-scrollbar
    width 0
    height 0
  &.showLeftMenu
    transform translate(-160px)
</style>
